home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1995 #5 & #6
/
Amiga Plus CD - 1995 - No. 5 and 6.iso
/
pd
/
daten
/
db
/
examples
/
arexxdemos
/
checkdate.db
< prev
next >
Wrap
Text File
|
1995-06-28
|
3KB
|
123 lines
/* checkdate.db
* ARexx script for the database program db. V1.0 David Ekholm, 1995
* Convert dates to the dd-Mmm-YY format. This code is in the public domain!
* You may easily adapt it to your favourite date format.
*
* Input rules:
* Days, months and years may be delimited by either a - or a / or nothing
* Days are accepted as either d or dd.
* Months are accepted as either m mm or mmm.
* Partly completed (non numeric) months are expanded (ie j -> JAN)
* Years are accepted as either yy or yyyy if a delimiter is used.
*
* Examples:
* 1195 1-Jan-95
* 10195 1-Jan-95
* 010195 1-Jan-95
* 15395 15-mar-95
* 1-jan-95 1-Jan-95
* 1-jan-1995 1-Jan-1995
* 29-2-95 error: February only has 28 days!
* 29-2-96 29-Feb-96 Ok, leap year!
* 29-f-96 29-Feb-96 Ok, leap year!
*
* If input doesn't conform to these rules, the screen will beep and you will have to try
* again
*/
options results
GETFIELD
indate = result
if indate ~= "" then do
outdate = convdate(indate)
if outdate == 'error' then do
DISPLAYBEEP
RETRYINPUT
end
else PUTFIELD outdate
end
exit
convdate: procedure
arg indate /* indate is now in UPPER case */
months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
lengths = "31 28 31 30 31 30 31 31 30 31 30 31"
leaps = "31 29 31 30 31 30 31 31 30 31 30 31"
umonths = upper(months)
savedate = indate
/* Change dd/mm/yy, dd-mm-yy or ddmmyy to dd mm yy */
if pos('/', indate) ~= 0 then
indate = translate(indate, ' ', '/')
else if pos('-', indate) ~= 0 then
indate = translate(indate, ' ', '-')
else do /* No delimiter */
len = length(indate)
if len == 4 then do
indate = insert(' ', indate, 2)
indate = insert(' ', indate, 1)
end
else
if len == 5 then do
indate = insert(' ', indate, 3)
indate = insert(' ', indate, 1)
/* fix month ambiguity (ie is '21393' 2-xxx-93 or 21-Mar-93 ?) */
month = word(indate,2)
if datatype(month, 'Whole') & month<1 | month>12 then do
indate = insert(' ', savedate, 3)
indate = insert(' ', indate, 2)
end
end
else if len == 6 then do
indate = insert(' ', indate, 4)
indate = insert(' ', indate, 2)
end
else return 'error'
end
/* Now parse the dd mm yy format */
if words(indate) ~= 3 then return 'error'
day = word(indate,1)
month = word(indate,2)
year = word(indate,3)
/* fix year */
if ~datatype(year,'Whole') then return 'error'
/* fix month */
if datatype(month,'Whole') then do
if month > 0 & month <= 12 then do
monthnum = month
month = word(months,month)
end
else return 'error'
end
else do
i = pos(month, umonths)
if i == 0 then return 'error'
monthnum = i % 4 + 1
month = subword(months, monthnum,1) /* Expand eg j to JAN */
end
/* fix day */
if datatype(day,'Whole') & day>0 then do
day = day + 0 /* Convert eg 01 to 1 */
if year // 4 == 0 then do /* Leap year */
if day > subword(leaps, monthnum,1) then return 'error'
end
else if day > subword(lengths, monthnum,1) then return 'error'
end
else return 'error'
/* Here we specify the returnformat. */
/* Use monthnum instead of month to get an all-numeric date */
return day || '-' || month || '-' || year